package com.ws.shop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ws.shop.bean.Page;
import com.ws.shop.dao.ArticleCategoriesDao;
import com.ws.shop.entity.ArticleCategories;
import com.ws.shop.service.ArticleCategoriesService;

@Service(value="articleCategoriesService")
public class ArticleCategoriesServiceImpl implements ArticleCategoriesService {
	@Resource(name="articleCategoriesDao")
	private ArticleCategoriesDao articleCategoriesDao;
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findArticleCategoriesListAll() {
		return articleCategoriesDao.findArticleCategoriesListAll();
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findCategoriesByfid(final long fid){
		return articleCategoriesDao.findCategoriesByfid(fid);
	}

	@Cacheable(value="articleCategories",key="'findById_'+#id")
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public ArticleCategories findArticleCategoriesById(int id) {
		return articleCategoriesDao.findArticleCategoriesById(id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page findArticleCategoriesListByPage(int pageno, int pagesize, String name) {
		return articleCategoriesDao.findArticleCategoriesListByPage(pageno,pagesize,name);
	}

	@Caching(evict={@CacheEvict(value="articleCategories",key="'findById_'+#articleCategories.id",condition="#articleCategories.id > 0"),@CacheEvict(value="articleCategoriesColl",allEntries=true)})
	@Transactional(rollbackFor=Exception.class)
	public void saveOrUpdate(ArticleCategories articleCategories) {
		articleCategoriesDao.saveOrUpdate(articleCategories);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findAllChildArticleCategoriesById(int id,
			int single) {
		return articleCategoriesDao.findAllChildArticleCategoriesById(id,single);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findArticleCategoriesTreeList() {
		return articleCategoriesDao.findArticleCategoriesTreeList();
	}

	@Cacheable(value="articleCategoriesColl")
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findArticleCategoriesParentTreeById(int id) {
		return articleCategoriesDao.findArticleCategoriesParentTreeById(id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findChildArticleCategoriesTreeById(int id) {
		return articleCategoriesDao.findChildArticleCategoriesTreeById(id);
	}

	@Cacheable(value="articleCategoriesColl")
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page findChildArticleCategoriesListPage(int pageno, int pagesize, int fid) {
		return articleCategoriesDao.findChildArticleCategoriesListPage(pageno,pagesize,fid);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findChildArticleCategoriesWithArticleById(
			int id) {
		return articleCategoriesDao.findChildArticleCategoriesWithArticleById(id);
	}

	@Cacheable(value="articleCategoriesColl")
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ArticleCategories> findBottomNavigationWithArticle(String acids) {
		return articleCategoriesDao.findBottomNavigationWithArticle(acids);
	}
}
